/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.shs.web.mydata;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.shs.entity.mydata.ShsMydata;
import com.thinkgem.jeesite.modules.shs.service.mydata.ShsMydataService;

/**
 * 我要数据Controller
 * @author lj
 * @version 2018-06-07
 */
@Controller
@RequestMapping(value = "${adminPath}/shs/mydata/shsMydata")
public class ShsMydataController extends BaseController {

	@Autowired
	private ShsMydataService shsMydataService;
	
	@ModelAttribute
	public ShsMydata get(@RequestParam(required=false) String id) {
		ShsMydata entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = shsMydataService.get(id);
		}
		if (entity == null){
			entity = new ShsMydata();
		}
		return entity;
	}
	
	@RequiresPermissions("shs:mydata:shsMydata:view")
	@RequestMapping(value = {"list", ""})
	public String list(ShsMydata shsMydata, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<ShsMydata> page = shsMydataService.findPage(new Page<ShsMydata>(request, response), shsMydata); 
		model.addAttribute("page", page);
		return "modules/shs/mydata/shsMydataList";
	}

	@RequiresPermissions("shs:mydata:shsMydata:view")
	@RequestMapping(value = "form")
	public String form(ShsMydata shsMydata, Model model) {
		model.addAttribute("shsMydata", shsMydata);
		return "modules/shs/mydata/shsMydataForm";
	}

	@RequiresPermissions("shs:mydata:shsMydata:edit")
	@RequestMapping(value = "save")
	public String save(ShsMydata shsMydata, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, shsMydata)){
			return form(shsMydata, model);
		}
		shsMydataService.save(shsMydata);
		addMessage(redirectAttributes, "保存我要数据成功");
		return "redirect:"+Global.getAdminPath()+"/shs/mydata/shsMydata/?repage";
	}
	
	@RequiresPermissions("shs:mydata:shsMydata:edit")
	@RequestMapping(value = "delete")
	public String delete(ShsMydata shsMydata, RedirectAttributes redirectAttributes) {
		shsMydataService.delete(shsMydata);
		addMessage(redirectAttributes, "删除我要数据成功");
		return "redirect:"+Global.getAdminPath()+"/shs/mydata/shsMydata/?repage";
	}

}